otcUE("content");

function otcUE(textAreaId) {
    UE.delEditor(textAreaId);
    UE.getEditor(textAreaId);
}

function messageReply() {
    let foodchainEditor = UE.getEditor('content', {
        toolbars:[
            'bold', 'italic', 'underline', '|', 'forecolor', 'backcolor', '|',
            'fontfamily', 'fontsize', '|',
            'jixinimage', 'emotion'
        ],
        elementPathEnabled: false,
        wordCount: false,
        focus: false,
        initialFrameHeight: 120
    });

    $.post(
        basePath + "workOrderReply/reply",
        {
            workOrderId: $("#workOrderId").val(),
            content: $($("#content").val()).text()
        },
        function (data) {
            data = eval("(" + data + ")");
            if (data.success) {
                foodchainEditor.execCommand("cleardoc");
                $("#message-reply").load(basePath + "workOrderReply/load?scroll=true&id=" + $("#workOrderId").val() + "&t=" + (new Date()).getTime());
            } else { $("#message").html(data.message); }

            //letScorllBottom();
        }
    );
}

function loadReply() {
    let workOrderId = $("#workOrderId").val();
    if ($.trim(workOrderId).length === 0) {
        return;
    }
    $("#message-reply").load(basePath + "workOrderReply/load?scroll=true&id=" + workOrderId + "&t=" + (new Date()).getTime());
    setTimeout(loadReply, 10000);
}

function letScorllBottom() {
    let messageReply = $("#message-reply");
    let scrollTop = messageReply[0].scrollHeight;
    messageReply.scrollTop(scrollTop);
}

$(function() { loadReply(); });